// import 'package:xbaistack/common/router.dart';

import 'package:xbaistack/common/gen.dart';
import 'package:xbaistack/page/click_page.dart';
import 'package:xbaistack/page/customer_keyword_page.dart';
import 'package:xbaistack/page/demo.dart';
import 'package:xbaistack/page/form_page.dart';
import 'package:xbaistack/page/icon_page.dart';
import 'package:xbaistack/page/maodian_page.dart';
import 'package:xbaistack/page/picker_page.dart';
import 'package:xbaistack/page/pubbu_page.dart';
import 'package:xbaistack/page/refresh_demo.dart';
import 'package:xbaistack/page/select_langue.dart';
import 'package:xbaistack/page/setting_theme.dart';
import 'package:xbaistack/page/swiper_page.dart';
import 'package:xbaistack/page/tabbar_page/tabbar_page.dart';
import 'package:xbaistack/page/text_page.dart';
import 'package:xbaistack/page/tools.dart';
import 'package:flutter/material.dart';
import 'package:xbaistack/page/tost_page.dart';
import 'package:xbaistack/page/webview_page.dart';
import 'package:xbaistack/router.dart';
import 'package:xbaistack/utils/helper.dart';

class DemoPageType {
  final String title;
  final Type page;

  const DemoPageType({required this.title, required this.page});
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();
    // MyRouter.ROUTES.forEach((key, value) {
    //   print("路由：$key -> ${value.call(context).runtimeType}");
    // });
  }

  @override
  Widget build(BuildContext context) {
    final List<DemoPageType> _pageDemoList = [
      DemoPageType(title: '列表页面封装', page: RefreshDemoPage),
      DemoPageType(title: 'tabbar使用', page: TabbarPage),
      DemoPageType(title: '万能点击组件', page: ClickPage),
      DemoPageType(title: '自定义键盘', page: CustomizeKeyboard),
      DemoPageType(title: 'icon使用', page: IconPage),
      DemoPageType(title: '导航锚点', page: MyNavigatorPage),
      DemoPageType(title: '选择器使用', page: PickerPage),
      DemoPageType(title: '瀑布流页面', page: PubuPage),
      DemoPageType(title: '选择语言', page: SelectLanguePage),
      DemoPageType(title: '设置主题', page: SettingThemePage),
      DemoPageType(title: '轮播图', page: SwiperPage),
      DemoPageType(title: 'toast显示', page: ToastPage),
      DemoPageType(title: 'teex_field Demo', page: TextPage),
      DemoPageType(title: 'form表单页面', page: FormPage),
    ];
    return Center(
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Wrap(
          spacing: 20,
          children: [
            ..._pageDemoList.map((item) {
              return ElevatedButton(
                onPressed: () {
                  // context.routeTo(RefreshDemoPage);
                  context.routeTo(item.page);
                },
                child: Text(item.title),
              );
            }).toList(),
            ElevatedButton(
              onPressed: () {
                context
                    .routeOf<WebViewPage>()
                    .arguments(
                      WebProp(url: 'https://www.baidu.com/', title: '测试'),
                    )
                    .to();
              },
              child: const Text('跳转到webview'),
            ),
          ],

          //  [

          //   ElevatedButton(
          //     onPressed: () {
          //       // MyRouter.push(context, MyRouter.INDEX);
          //     },
          //     child: const Text('跳转到主页'),
          //   ),
          //   const SizedBox(width: 20),
          //   ElevatedButton(
          //     onPressed: () {
          //       // MyRouter.push(context, MyRouter.DEMO);
          //     },
          //     child: const Text('跳转到演示页面'),
          //   ),
          // ],
        ),
      ),
    );
  }
}
